﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Sys.WebRes.Data;

namespace Sys.WebRes.Publish.Areas.Admin.Models
{
    public class AttachmentModel
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Summary { get; set; }
        public string Folder { get; set; }
        public string FileName { get; set; }
        public string Extension { get; set; }
        public int? PicWidth { get; set; }
        public int? PicHeight { get; set; }
        public string CustomType { get; set; }
        public DateTime CreateDate { get; set; }

        public string FilePath 
        { 
            get 
            {
                if (!string.IsNullOrEmpty(this.FileName))
                {
                    return Path.Combine(Folder ?? "", FileName ?? "");
                }
                else
                {
                    return string.Empty;
                }
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this.FileName = Path.GetFileName(value);
                    this.Extension = Path.GetExtension(this.FileName);
                    this.Folder = Path.GetDirectoryName(value);
                }
            }
        }
        public string ThumbPath { get { return Path.Combine(Folder ?? "", SysConfig.ThumbPrefix + (FileName ?? SysConfig.DefaultPicture)); } }
        public string PicSize { get { return PicWidth==null?"":string.Format("{0}×{1}", PicWidth, PicHeight); } }
        public string CDateString { get { return CreateDate.ToString("yyyy/MM/dd hh:mm:ss"); } }
        public int OrderNo { get; set; }
        public bool DeleteFlag { get; set; }
    }
}